package io.renren.service.impl;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.dao.AppCommentDao;
import io.renren.dto.AppCommentDto;
import io.renren.entity.AppComment;
import io.renren.service.AppCommentService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service("appCommentService")
public class AppCommentServiceImpl extends ServiceImpl<AppCommentDao, AppComment> implements AppCommentService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Page<AppComment> page = this.selectPage(
                new Query<AppComment>(params).getPage(),
                new EntityWrapper<>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<AppCommentDto> queryAppCommentList( Integer page, Integer limit, Integer appId) {
        Page<AppCommentDto> p = new Page<>( page, limit );
        p = baseMapper.queryAppCommentPage( p, appId );
        if( p.getRecords() == null ){
            return new ArrayList<>();
        }
        return  p.getRecords();
    }
}
